<title>会员管理</title>
  
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>视频记录</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-videofront-formlist">
      <div class="layui-form-item">
        <div class="layui-inline">
          <button class="layui-btn layui-btn-warm layuiadmin-btn-update" lay-filter="LAY-user-front-update">
            <i class="layui-icon layui-icon-refresh layuiadmin-button-btn"></i>
            批量更新统计<span class="layui-badge layui-bg-black" id="percent" style="display:none;"></span>
          </button>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">活动名称</label>
          <div class="layui-input-block">
            <input type="text" name="title" placeholder="请输入活动名称" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">商家手机号</label>
          <div class="layui-input-block">
            <input type="text" name="mobile" placeholder="请输入商家手机号" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <button class="layui-btn layuiadmin-btn-video" lay-submit lay-filter="LAY-user-front-search">
            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
          </button>
        </div>
      </div>
    </div>
    
    <div class="layui-card-body">
      <center style="color:#FF5722">数据为最近30天的统计数据，且需要手动更新。</center>
      <table id="LAY-video-manage" lay-filter="LAY-video-manage"></table>
      <script type="text/html" id="imgTpl">
        {{# var member=JSON.parse(d.member) }}
        <img style="display:inline-block;width:30px;height:30px" src= {{ member.avatar }} >
        {{ member.nickname }}
      </script> 
      <script type="text/html" id="vstatusTpl">
        {{# if(d.status==0){ }}
        <span class="layui-badge layui-bg-cyan">失败或删除</span>
        {{# }else{ }}
        <span class="layui-badge layui-bg-blue">发送成功</span>
        {{# } }}
      </script> 
      <script type="text/html" id="timeTpl"> 
        {{# var date = new Date(d.createtime * 1000);
          var dt = date.getFullYear() + '-';
          dt += (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
          dt += (Array(2).join(0) + date.getDate()).slice(-2) + ' ';
          dt += (Array(2).join(0) + date.getHours()).slice(-2) + ':';
          dt += (Array(2).join(0) + date.getMinutes()).slice(-2) + ':';
          dt += (Array(2).join(0) + date.getSeconds()).slice(-2); }}
        {{ dt }}
      </script> 
      <script type="text/html" id="time2Tpl">
        {{# if(d.updatetime==0){ }}
        -
        {{# }else{ }}
        {{# var date = new Date(d.updatetime * 1000);
          var dt = date.getFullYear() + '-';
          dt += (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
          dt += (Array(2).join(0) + date.getDate()).slice(-2) + ' '; }}
        {{ dt }}
        {{# } }}
      </script> 
      <script type="text/html" id="table-video-webuser">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="update"><i class="layui-icon layui-icon-refresh"></i>更新</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
      </script>
    </div>
  </div>
</div>

<script>
layui.use('video', layui.factory('video')).use(['admin', 'video', 'table'], function(){
  var $ = layui.$
  ,admin = layui.admin
  ,view = layui.view
  ,table = layui.table
  ,form = layui.form;
  
  form.render(null, 'layadmin-videofront-formlist');
  
  //监听搜索
  form.on('submit(LAY-user-front-search)', function(data){
    var params = [];
    for (let key in data.field) {
      params.push(key+'='+data.field[key]);
    }
    //执行重载
    table.reload('LAY-video-manage', {
      url: layui.setter.baseUrl+"video/index?"+params.join('&')
    });
  });
  
  $('.layui-btn.layuiadmin-btn-video').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });

  $('.layui-btn.layuiadmin-btn-update').on('click', function(){
    var checkStatus = table.checkStatus('LAY-video-manage'),data = checkStatus.data;
    var i=1, num=data.length;
    $('#percent').show().text('0/'+num);
    for (let index = 0; index < data.length; index++) {
      $.post(
          layui.setter.baseUrl+'video/getdata',
          {id: data[index].id},
          function(ret){
            if(i<num){
              i++;
              $('#percent').text(i+'/'+num);
            }
          }
      );
    }
    if(num > 0){
      var sv = setInterval(function(){
        if(i>=num){
          clearInterval(sv);
          layer.msg('更新完毕');
          $('#percent').hide().text('');
          i=1;
          layui.table.reload('LAY-video-manage');
        }
      },500);
    }else{
      $('#percent').hide().text('');
    }
  });
});
</script>